package svc

import (
	"go-zero-mall/app/product/cmd/rpc/internal/config"
	"go-zero-mall/app/product/model"

	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
)

type ServiceContext struct {
	Config                                   config.Config
	RedisClient                              *redis.Redis
	PmsAlbumModel                            model.PmsAlbumModel
	PmsAlbumPicModel                         model.PmsAlbumPicModel
	PmsBrandModel                            model.PmsBrandModel
	PmsCommentModel                          model.PmsCommentModel
	PmsCommentReplayModel                    model.PmsCommentReplayModel
	PmsFeightTemplateModel                   model.PmsFeightTemplateModel
	PmsMemberPriceModel                      model.PmsMemberPriceModel
	PmsProductAttributeCategoryModel         model.PmsProductAttributeCategoryModel
	PmsProductAttributeModel                 model.PmsProductAttributeModel
	PmsProductAttributeValueModel            model.PmsProductAttributeValueModel
	PmsProductCategoryAttributeRelationModel model.PmsProductCategoryAttributeRelationModel
	PmsProductCategoryModel                  model.PmsProductCategoryModel
	PmsProductFullReductionModel             model.PmsProductFullReductionModel
	PmsProductLadderModel                    model.PmsProductLadderModel
	PmsProductModel                          model.PmsProductModel
	PmsProductOperateLogModel                model.PmsProductOperateLogModel
	PmsProductVertifyRecordModel             model.PmsProductVertifyRecordModel
	PmsSkuStockModel                         model.PmsSkuStockModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	sqlConn := sqlx.NewMysql(c.DB.DataSource)
	return &ServiceContext{
		Config: c,
		RedisClient: redis.New(c.Redis.Host, func(r *redis.Redis) {
			r.Type = c.Redis.Type
			r.Pass = c.Redis.Pass
		}),
		PmsAlbumModel:                            model.NewPmsAlbumModel(sqlConn, c.Cache),
		PmsAlbumPicModel:                         model.NewPmsAlbumPicModel(sqlConn, c.Cache),
		PmsBrandModel:                            model.NewPmsBrandModel(sqlConn, c.Cache),
		PmsCommentModel:                          model.NewPmsCommentModel(sqlConn, c.Cache),
		PmsCommentReplayModel:                    model.NewPmsCommentReplayModel(sqlConn, c.Cache),
		PmsFeightTemplateModel:                   model.NewPmsFeightTemplateModel(sqlConn, c.Cache),
		PmsMemberPriceModel:                      model.NewPmsMemberPriceModel(sqlConn, c.Cache),
		PmsProductAttributeCategoryModel:         model.NewPmsProductAttributeCategoryModel(sqlConn, c.Cache),
		PmsProductAttributeModel:                 model.NewPmsProductAttributeModel(sqlConn, c.Cache),
		PmsProductAttributeValueModel:            model.NewPmsProductAttributeValueModel(sqlConn, c.Cache),
		PmsProductCategoryAttributeRelationModel: model.NewPmsProductCategoryAttributeRelationModel(sqlConn, c.Cache),
		PmsProductCategoryModel:                  model.NewPmsProductCategoryModel(sqlConn, c.Cache),
		PmsProductFullReductionModel:             model.NewPmsProductFullReductionModel(sqlConn, c.Cache),
		PmsProductLadderModel:                    model.NewPmsProductLadderModel(sqlConn, c.Cache),
		PmsProductModel:                          model.NewPmsProductModel(sqlConn, c.Cache),
		PmsProductOperateLogModel:                model.NewPmsProductOperateLogModel(sqlConn, c.Cache),
		PmsProductVertifyRecordModel:             model.NewPmsProductVertifyRecordModel(sqlConn, c.Cache),
		PmsSkuStockModel:                         model.NewPmsSkuStockModel(sqlConn, c.Cache),
	}
}
